package our.pack;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;




public class RenameTrackActivity extends Activity {

	TracksDataSource trackDatasource;
	PointsDataSource pointsDatasource;
	EditText editTrackNaam;
	TextView trackNaam;
	Track track;
	Button save;
	
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.renametrack);
		
		trackDatasource = new TracksDataSource(this);
		trackDatasource.open();
		pointsDatasource = new PointsDataSource(this);
		pointsDatasource.open();
		
		Intent i = getIntent();
		Bundle b = i.getExtras();
		
		track = (Track) b.get("Track");
		
		trackNaam = (TextView)findViewById(R.id.textnametrack);
		editTrackNaam = (EditText) findViewById(R.id.edittrackname);
		save = (Button)findViewById(R.id.savebutton);
		
		trackNaam.setText(track.getTrackName());
		
		KlikLuister kl = new KlikLuister();
		save.setOnClickListener(kl);
		
		
		
	}
	
	private class KlikLuister implements OnClickListener{

		public void onClick(View v) {
			if(v.getId() == R.id.savebutton){
				Log.d("renametrackactivity", track.getTrackName());
				trackDatasource.renameTrack(track, editTrackNaam.getText().toString());
				setResult(999);
				finish();
			}
			
		}
		
	}
	
}
